<template>
	<view class="home">
		<MySearch @click="toSearch"></MySearch>
		<swiper circular :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-color="white">
			<swiper-item v-for="item in swiperList" :key="item.goods_id">
				<navigator :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`"><image mode="widthFix" :src="item.image_src"></image></navigator>
			</swiper-item>
		</swiper>
		<view class="nav_list">
			<view class="nav_item" v-for="(item,index) in navList" :key="index" @click="navCate(item)">
					<image :src="item.image_src"></image>
			</view>
		</view>
		<view class="floor_box">
			<view class="floor_item"  v-for="(item,index) in floorList" :key="index">
				<!-- 标题 -->
				<image :src="item.floor_title.image_src" mode="widthFix"></image>
				<view class="floor_img_box">
					<view class="left_img_box">
						<image @click="toList(item.product_list[0])" :src="item.product_list[0].image_src" mode=""></image>
					</view>
					<view class="right_img_box">
					  <image @click="toList(item.product_list[1])" :src="item.product_list[1].image_src"></image>
					  <image @click="toList(item.product_list[2])" :src="item.product_list[2].image_src"></image>
					  <image @click="toList(item.product_list[3])" :src="item.product_list[3].image_src"></image>
					  <image @click="toList(item.product_list[4])" :src="item.product_list[4].image_src"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			swiperList: [],
			navList:[],
			floorList:[]
		}
	},
	onLoad() {
		this.getSwiperList()
		this.getNavList()
		this.getFloorList()
	},
	methods: {
		// 获取轮播图
		async getSwiperList() {
			const { data: res } = await uni.$http.get('/home/swiperdata')
			// console.log(uni)
			if (res.meta.status !== 200) return uni.$total('请求数据失败')
			// console.log(res)
			this.swiperList = res.message
		},
		// 获取 nav 栏数据
		async getNavList() {
			const { data: res } = await uni.$http.get('/home/catitems')
			// console.log(res)
			this.navList=res.message
		},
		// 点击 分类图标跳转到分类
		navCate(item){
			if(item.name==='分类'){
				uni.switchTab({url:'/pages/cate/cate'})
			}
		},
		// 获取楼层列表
		async getFloorList(){
			const {data:res} = await uni.$http.get('/home/floordata')
			console.log(res)
			if (res.meta.status !== 200) return uni.$total('请求数据失败')
			this.floorList=res.message
		},
		// 跳转到列表页
		toList(item){
			const queryId = item.navigator_url.substring(item.navigator_url.indexOf('?'))
			uni.navigateTo({
				url: '/subpkg/goods_list/goods_list'+queryId,
			});
			
		},
		// 点击子组件触发父组件方法
		toSearch(){
			uni.navigateTo({
				url:'/subpkg/search/search'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.home {
	swiper {
		image {
			width: 100%;
			height: 280rpx;
		}
	}
	.nav_list{
		display: flex;
		justify-content: space-around;
		.nav_item{
			margin: 10rpx 25rpx;
		}
		image{
			width: 128rpx;
			height: 140rpx;
		}
	}
	.floor_img_box{
		display: flex;
		height: 410rpx;
		 .left_img_box {
		    flex:1;
		    image {
		      width: 100%;
		      height: 202px;
		    }
		  }
		  .right_img_box {
		    flex: 2;
		    image {
		      width: 50%;
		      height: 100px;
		    }
		  }
	}
}
</style>
